<template>
	<view class="home">
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="item in swiper" :key="item.id">
				
					<image :src="item.img" mode=""></image>
				
			</swiper-item>
			
		</swiper>
		
		<!-- 导航 -->
		<view class="nav">
			<view class="nav_item" v-for="(nav,index) in navs" :key="index" @click="navItemClick(index)">
				<view :class="nav.iconClass"></view>
				<text>{{nav.title}}</text>
			</view>
		
			
		</view>
		<!-- 推荐商品 -->
		<view class="hot_goods">
			<view class="tit">
				推荐商品
			</view>
			<goodList :hotGoods="hotGoods" @itemClick="goGoodsDetail"></goodList>
		
			
		</view>
	</view>
</template>

<script>
	import goodList from '@/pages/components/good_list.vue'
	export default {
		data() {
			return {
				swiper:[],
				hotGoods:[],
				navs:[
					{
						title:'精品超市',
						iconClass:'iconfont icon-ziyuan',
						link_url:'/pages/goods/goods',
						
					},
					{
						title:'联系我们',
						iconClass:'iconfont icon-guanyuwomen',
						link_url:'/pages/contact/contact',
						
					},
					{
						title:'社区图片',
						iconClass:'iconfont icon-tupian',
						link_url:'/pages/pics/pics',
						
					},
					{
						title:'学习视频',
						iconClass:'iconfont icon-shipin',
						link_url:'/pages/video/video',
						
					},
				]
				
			}
		},
		onLoad() {
			this.getlunbo()
			this.getgoodslist()

		},
		components:{
			goodList
		},
		
		methods: {
			async getlunbo(){
				const res= await this.$myRequest({
					url:'/api/getlunbo'
				}) 
				this.swiper = res.data.message
				console.log(this.swiper);
			},
			async getgoodslist(){
				const res = await this.$myRequest({
					url:'/api/getgoods?pageindex=1'
				})
				this.hotGoods = res.data.message
				
			},
			navItemClick(index){
				uni.navigateTo({
					url:this.navs[index].link_url
				})
			},
			goGoodsDetail(id){
				uni.navigateTo({
					url:'/pages/goodsDetail/goodsDetail?id='+id
				})
			}

		}
	}
</script>

<style lang="scss">
	.home{
		swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				height: 100%;
				width: 100%;
			}
		}
		.nav{
			
			display: flex;
		
			.nav_item{
				width: 25%;
		
				text-align: center;
	
				view{
					height: 120rpx;
					width: 120rpx;
					background-color:#fbb ;
					border-radius: 50%;
					margin: 10px auto;
					line-height: 120rpx;
					color: #fff;
					font-size: 50rpx;
				}
				
				text{
					font-size: 30rpx;
				}
			}
			
		}
	
		.hot_goods{
			background-color: #eee;
			overflow: hidden;
			margin-top:10px ;
			.tit{
				color: #fbb;
				
				height: 50px;
				line-height: 50px;
				text-align: center;
				letter-spacing: 20px;
				background-color: #fff;
				margin: 7rpx 0;
			}
			
			
			
		}
	
	
	
	
	
	
	
	
	
	
	
	}

</style>
